<?php

class Application_Model_ExplicitCatanTypeMapper {

    protected $_dbTable;

    public function getDbTable() {
        if (null === $this->_dbTable) {
            $this->setDbTable('Application_Model_DbTable_ExplicitCatanType');
        }
        return $this->_dbTable;
    }

    public function setDbTable($dbTable) {
        if (is_string($dbTable)) {
            $dbTable = new $dbTable();
        }
        if (!$dbTable instanceof Zend_Db_Table_Abstract) {
            throw new Exception('Ungueltige Gateway-Klasse fuer Tabellendaten');
        }
        $this->_dbTable = $dbTable;
    }

    public function find($id, Application_Model_ExplicitCatanTypeModel $type) {
        $result = $this->getDbTable()->find($id);
        if (0 == count($result)) {
            return null;
        }
        $row = $result->current();
        $type->setId($row['id'])
                ->setName($row['name'])
                ->setHas_street($row['has_street'])
                ->setHas_knight($row['has_knight'])
                ->setPlayers($row['players'])
                ->setPoints($row['points'])
                ->setInfo($row['info']);

        return $type;
    }

    public function fetchAll($where = null, $order = null, $count = null, $offset = null) {
        $resultSet = $this->getDbTable()->fetchAll($where, $order, $count, $offset);
        $entries = array();
        foreach ($resultSet as $row) {
            $entry = new Application_Model_ExplicitCatanTypeModel();
            $entry->setId($row['id'])
                    ->setName($row['name'])
                    ->setHas_street($row['has_street'])
                    ->setHas_knight($row['has_knight'])
                    ->setPlayers($row['players'])
                    ->setPoints($row['points'])
                    ->setInfo($row['info']);
            $entries[] = $entry;
        }
        return $entries;
    }

    
    
    
}

